/*
Operations with images

http://docs.opencv.org/3.2.0/d5/d98/tutorial_mat_operations.html
Data:2017.04.24

*/

#include <opencv2/opencv.hpp>
#include <iostream>

using namespace cv;
using namespace std;


int main( int argc, char* argv[])
{
    //读
    Mat img = imread("../data/image.jpg", IMREAD_COLOR);
    Mat img_gray = imread("../data/image.jpg", IMREAD_GRAYSCALE);

    imshow("image", img);
    waitKey();
    //写
//    imwrite("../data/new_image.jpg", img);

    int x = 5;
    int y = 10;

    Vec3b intensity = img.at<Vec3b>(y, x);
    uchar blue = intensity.val[0];
    uchar green = intensity.val[1];
    uchar red = intensity.val[2];
    cout << "bule: " << int(blue) << " green: " << int(green) << " red: " << int(red) << endl;


    Scalar intensity2 = img_gray.at<uchar>(y, x);

    cout << "gray: " << intensity2.val[0] << endl;

    //改
    img_gray.at<uchar>(y, x) = 128;

    Rect r(10, 10, 500, 500);
    Mat smallImg = img(r);
    imshow("image", smallImg);
    waitKey();

    Mat img2 = img.clone();
    img2 = Scalar(0);

    imshow("image", img2);
    waitKey();

    //转换
    IplImage ipl = img;
    CvMat m = img;
    //cvtColor(img, grey, COLOR_BGR2GRAY);
    //src.convertTo(dst, CV_32F);


    return 0;
}
